package com.ruoyi.loginfo.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loginfo.domain.LogCompany;
import com.ruoyi.loginfo.service.ILogCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物流公司Controller
 * 
 * @author ruoyi
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/company")
public class LogCompanyController extends BaseController
{
    @Autowired
    private ILogCompanyService logCompanyService;

    /**
     * 查询物流公司列表
     */
    @RequiresPermissions("loginfo:company:list")
    @GetMapping("/list")
    public TableDataInfo list(LogCompany logCompany)
    {
        startPage();
        List<LogCompany> list = logCompanyService.selectLogCompanyList(logCompany);
        return getDataTable(list);
    }

    /**
     * 导出物流公司列表
     */
    @RequiresPermissions("loginfo:company:export")
    @Log(title = "物流公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LogCompany logCompany)
    {
        List<LogCompany> list = logCompanyService.selectLogCompanyList(logCompany);
        ExcelUtil<LogCompany> util = new ExcelUtil<LogCompany>(LogCompany.class);
        util.exportExcel(response, list, "物流公司数据");
    }

    /**
     * 获取物流公司详细信息
     */
    @RequiresPermissions("loginfo:company:query")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(logCompanyService.selectLogCompanyByCompanyId(companyId));
    }

    /**
     * 新增物流公司
     */
    @RequiresPermissions("loginfo:company:add")
    @Log(title = "物流公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LogCompany logCompany)
    {
        return toAjax(logCompanyService.insertLogCompany(logCompany));
    }

    /**
     * 修改物流公司
     */
    @RequiresPermissions("loginfo:company:edit")
    @Log(title = "物流公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LogCompany logCompany)
    {
        return toAjax(logCompanyService.updateLogCompany(logCompany));
    }

    /**
     * 删除物流公司
     */
    @RequiresPermissions("loginfo:company:remove")
    @Log(title = "物流公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(logCompanyService.deleteLogCompanyByCompanyIds(companyIds));
    }
}
